package xw.qxypt.modules.baseinfo.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import xw.qxypt.common.utils.PageUtils;
import xw.qxypt.common.utils.Query;

import xw.qxypt.modules.baseinfo.dao.LhpWaysectRoleDao;
import xw.qxypt.modules.baseinfo.entity.LhpUserWaysectroleRelationEntity;
import xw.qxypt.modules.baseinfo.entity.LhpWaysectRoleEntity;
import xw.qxypt.modules.baseinfo.service.LhpUserWaysectroleRelationService;
import xw.qxypt.modules.baseinfo.service.LhpWaysectRoleService;
import xw.qxypt.modules.sys.shiro.ShiroUtils;


@Service("lhpWaysectRoleService")
public class LhpWaysectRoleServiceImpl extends ServiceImpl<LhpWaysectRoleDao, LhpWaysectRoleEntity> implements LhpWaysectRoleService {
    @Autowired
    private LhpUserWaysectroleRelationService lhpUserWaysectroleRelationService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<LhpWaysectRoleEntity> page = this.page(
                new Query<LhpWaysectRoleEntity>().getPage(params),
                new QueryWrapper<LhpWaysectRoleEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<LhpWaysectRoleEntity> getByUserId() {
        List<LhpUserWaysectroleRelationEntity> userlist=lhpUserWaysectroleRelationService.list(
                new QueryWrapper<LhpUserWaysectroleRelationEntity>()
                        .in("USER_ID", ShiroUtils.getUserId())
        );
        List<String> ids=new ArrayList<>();
        for (LhpUserWaysectroleRelationEntity e:userlist) {
            ids.add(e.getRoleId());
        }
        //根据用户id从关联关系中查询路段角色id列表
        List<LhpWaysectRoleEntity> list=this.list(
                new QueryWrapper<LhpWaysectRoleEntity>()
                        .in("id", ids)
        );
        return list;
    }

}
